<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增发布广告')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-advertisement-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">广告名字：</label>
                <div class="col-sm-8">
                    <input name="adName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">广告类型：</label>
                <div class="col-sm-8">
                    <select name="adType" required class="form-control m-b" th:with="type=${@dict.getType('ad_type')}">
                        <option value="">所有</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">投放机器类型：</label>
                <div class="col-sm-8">
                    <select name="putType" required class="form-control m-b" th:with="type=${@dict.getType('ad_putType')}">
                        <option value="">所有</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">投放位置：</label>
                <div class="col-sm-8">
                    <select name="positionType" required class="form-control m-b" th:with="type=${@dict.getType('ad_position_type')}">
                        <option value="">所有</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">选择楼栋：</label>
                <div class="col-sm-8">
                    <select name="floorId" onchange="floorChange()" id="floorId" class="form-control m-b">
                        <option  value="">请选择</option>
                        <option th:each="floor : ${floorSelect}"  th:text="${floor.name}" th:value="${floor.floorId}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">单元id：</label>
                <div class="col-sm-8">
                    <select name="unitId"  id="unitId" class="form-control m-b">
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">播放顺序：</label>
                <div class="col-sm-8">
                    <input name="sort" class="form-control" type="number" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">播放方式：</label>
                <div class="col-sm-8">
                    <select name="modeType" required class="form-control m-b" th:with="type=${@dict.getType('ad_mode_type')}">
                        <option value="">所有</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">开始时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="beginTime" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">结束时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="endTime" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">备注：</label>
                <div class="col-sm-8">
                    <input name="remark" class="form-control" type="text" >
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
        var prefix = ctx + "wisdom/advertisement"
        $("#form-advertisement-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-advertisement-add').serialize());
            }
        }

        $("input[name='beginTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        function floorChange(){
            var fid=$("#floorId").val();
            $.ajax({url:"/system/room/untilSelect",type:"get",data:"floorId="+fid,async:true,success:function (reslut) {
                    if (reslut!="") {
                        $("#unitId").text("");

                        $("#unitId").append("<option selected='selected' value=''>请选择</option>");
                        $.each($.parseJSON(reslut), function (index, item) {

                            $("#unitId").append("<option  value='" + item.unitId + "'>" + item.unitNum + "</option>");

                        });
                    }else{
                        $("#unitId").text("");
                    }

                },error:function (reslut) {
                    layer.msg("操作失败", {icon: 2});
                }
            });
        }
        $("input[name='endTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>